const app = getApp()

Page({
  data: {
    listData: [],
    companyList: [],
    searchValue: '',
  },
  onLoad() {
    this.getList();
  },
  // 取消关注
  cancelFollow: function(e) {
    let id = e.currentTarget.dataset.id,
      _this = this;
    wx.showModal({
      content: "是否取消关注",
      success: function(res) {
        if (res.confirm) {
          app.util.ajax({
            url: 'user/cancelFollow',
            data: {
              id: id
            },
            success: function(data) {
              // wx.showToast({
              //     title:'已经取消关注'
              // });
              _this.getList();
            }
          })
        }
      }
    })
  },
  // 获取关注列表
  getList: function() {
    let _this = this;
    app.util.ajax({
      url: 'user/follow',
      data: {
        user_id: app.globalData.userInfo.user_id
      },
      success: function(res) {
        let listData = res.enterprise,
          companyList = res.company;
        if (res.state == 1) {
          wx.showToast({
            title: res.info,
            icon: 'none'
          })
          listData = [];
          companyList = [];
        }
        _this.setData({
          listData: listData,
          companyList: companyList
        })
      }
    })
  },
  // 分享
  onShareAppMessage(res) {
    return {
      title: '广州大学校友会校友企业家专委会',
      path: '/pages/index/index'
    }
  },
  // 获取搜索框内容
  changeInputValue: function(e) {
    this.setData({
      searchValue: e.detail.value
    })
  },
  // 提交搜索
  submitSearch: function() {
    let value = this.data.searchValue,
      _this = this;
    app.util.ajax({
      url: 'user/follow',
      data: {
        name: value,
        user_id: app.globalData.userInfo.user_id
      },
      success: function(res) {
        let listData = res.enterprise,
          companyList = res.company;
        if (!listData && !companyList) {
          wx.showToast({
            title: '没有查询结果',
            icon: 'none'
          })
          listData = [];
          companyList = [];
        }
        _this.setData({
          listData: listData,
          companyList: companyList
        })
      }
    })
  },
  // 查看名片
  seeUserCard: function(e) {
    // let id = e.currentTarget.dataset.id,
    //     state = e.currentTarget.dataset.type;
    //     wx.navigateTo({
    //     url:'/pages/index/listMsg/listMsg?state='+state+'&id='+id
    // })
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/index/listMsg/listMsg?type=1&id=' + id
    })
  }
})